/*
 * @Author: wuqingchun
 * @Date: 2023-08-17 10:54:06
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-01-08 10:14:44
 */
#ifndef __FTPC_BUF_H__
#define __FTPC_BUF_H__

typedef struct tagFTPCBuf
{
    char *pcBuf;
    size_t ulDataSize;
    struct tagFTPCBuf* pstNext;
}FTPC_BUF_S;

typedef struct tagFTPCBufHead
{
    size_t ulBufSize;
    FTPC_BUF_S* pstHead;
    FTPC_BUF_S* pstTail;
}FTPC_BUF_HEAD_S;

inline static void FTPC_buf_Init(FTPC_BUF_HEAD_S* pstBufHead, size_t ulBufSize)
{
    pstBufHead->ulBufSize = ulBufSize;
    pstBufHead->pstHead = NULL;
    pstBufHead->pstTail = NULL;
}

inline static void FTPC_buf_Reset(FTPC_BUF_HEAD_S* pstBufHead)
{
    if (pstBufHead->pstHead == NULL)
    {
        pstBufHead->pstTail = NULL;
    }
}

FTPC_BUF_S* FTPC_buf_Get(FTPC_BUF_HEAD_S* pstBufHead);

inline static size_t FTPC_buf_GetSize(FTPC_BUF_HEAD_S* pstBufHead)
{
    return pstBufHead->ulBufSize - pstBufHead->pstTail->ulDataSize - 1;
}

inline static size_t FTPC_buf_GetTotalDataSize(FTPC_BUF_HEAD_S* pstBufHead)
{
    FTPC_BUF_S* pstBuf = pstBufHead->pstHead;
    size_t ulTotalSize = 0;

    while (pstBuf != NULL)
    {
        ulTotalSize += pstBuf->ulDataSize;
        pstBuf = pstBuf->pstNext;
    }

    return ulTotalSize;
}

void FTPC_buf_Fini(FTPC_BUF_HEAD_S* pstBufHead);

#endif //__FTPC_BUF_H__